package com.lanhai.fnstore.thirdpart;

import com.lanhai.fnstore.Tools;

/**
 * 仓库上料
 * 
 * @author virus408
 *
 */
public class StoreIn implements StationInterface {

	@Override
	public byte[] applyTransfer(int line, ApplyTransferEnum type) {

		// 0x00,线别 ,0x00,指令
		byte[] buf = new byte[] { 0x00, (byte) line, 0x00, 0x00, 0x00, 0x01 };
		return buf;
	}

	@Override
	public byte[] clear(int line) {
		byte[] buf = new byte[] { 0x00, (byte) line, 0x00, 0x00, 0x00, 0x00 };
		return buf;

	}

	@Override
	public byte[] applyLeave(int line, ApplyTransferEnum type) {
		byte[] buf = new byte[] { 0x00, (byte) line, 0x00, 0x00, 0x00, 0x02 };
		return buf;
	}

	@Override
	public StationData resoleveData(byte[] buf) {
		StationData obj = new StationData();
		obj.setLine(buf[1]);
		// 0x00,线别 ,0x00,数量,0x00,指令
		/*
		  01=有料
		  02=可离开
		  04=可传输
		  03=异常（也不会给异常）
		 */
		obj.setCmdStr(Tools.byte2HexStr(buf));
		if (buf[5] == 0x03) {
			// 机台异常
			obj.setEventType(StationDataEnum.Error);
			return obj;
		}
		if (buf[5] == 0x02) {
			// 允许 离开
			obj.setEventType(StationDataEnum.AllowLeave);
			return obj;
		}
		 if(buf[5]==0x04) {
			 obj.setEventType(StationDataEnum.AllowTrans);
         } 
		if (buf[5] == 0x01) {
			obj.setEventType(StationDataEnum.Info);
		}
		// 允许传输的处理
		int num = buf[3];
		if (num > 10)
			num = 10;
		num = 10 - num;

		obj.setInNum(num);
		return obj;
	}

}
